package com.unieagle.exam.utils;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;


public final class UIUtils
{
    public static int dip2px(Context context, double dipValue)
    {
        float m = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * m + 0.5f);
    }

    public static int px2dip(Context context, double pxValue)
    {
        float m = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / m + 0.5f);
    }

    public static int sp2px(float spValue, float fontScale)
    {
        return (int) (spValue * fontScale + 0.5f);
    }

    public static int getDisplayHeight(Context c)
    {
        DisplayMetrics dm = c.getResources().getDisplayMetrics();
        return dm.heightPixels;
    }

    public static int getDisplayWidth(Context c)
    {
        DisplayMetrics dm = c.getResources().getDisplayMetrics();
        return dm.widthPixels;
    }
    
    public static Drawable getDefaultCheckBoxDrawable(Context ctx)
    {
	     int resID = 0;
	     if (Build.VERSION.SDK_INT <= 10)
	     {
	    	 resID = Resources.getSystem().getIdentifier("btn_check", "drawable", "android");
	     }
	     else
	     {
		     TypedValue value = new TypedValue();
		     ctx.getTheme().resolveAttribute(android.R.attr.listChoiceIndicatorMultiple, value, true);
		     resID = value.resourceId;
	     }
	     return ctx.getResources().getDrawable(resID);
    }

}
